package main.java.modules.alipay.util;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.demo.trade.config.Configs;
import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;

/**
 * 公共配置参数
 * @author D
 *
 */
public final class AlipayConfig {
	
	private AlipayConfig(){}
	
	//收款方账号
	public static final String SELLER_ID = "";
	
	//参数类型
	public static String PARAM_TYPE = "json";
	
	
	public static String CHARSET = "utf-8";
	
	/*
	 * 静态的内部类，只有被调用的时候才会加载，实现延迟加载
	 */
	public static class SingletonHolder {
		/**
		 * 静态初始化器  jvm保证线程安全
		 */
		//客户端实例
		private static AlipayClient alipayClient = new DefaultAlipayClient(Configs.getOpenApiDomain(),Configs.getAppid()
				,Configs.getPrivateKey(),PARAM_TYPE,CHARSET,Configs.getAlipayPublicKey());
		
		private static AlipayTradeService tradeService = new AlipayTradeServiceImpl.ClientBuilder().build();
	}
	
	/**
	 * 支付宝app请求客户端实例
	 * @return
	 */
	public static AlipayClient getAlipayClient() {
		return SingletonHolder.alipayClient;
	}
	
	/**
	 * 电脑端预下单
	 * @return
	 */
	public static AlipayTradeService getAlipayTradeService() {
		return SingletonHolder.tradeService;
	}
}
